package gdconf

import (
	"server_cluster/common/logger"
)

// 玩家等级配置表

type PlayerLevelConfig struct {
	Level    int32 `csv:"Level" gorm:"primary_key;autoIncrement:false"` // 等级
	Exp      int32 `csv:"Exp,omitempty"`                                // 升到下一等级所需经验
	SeverDay int32 `csv:"SeverDay,omitempty"`                           //开服天数
}

func (p *PlayerLevelConfig) TableName() string {
	return "config_player_level"
}

func (g *GameDataConfig) savePlayerLevelConfig() {
	saveTableToDb[PlayerLevelConfig](g.Db, readTable[PlayerLevelConfig](g.CsvPathPrefix+"player.csv"))
}

func (g *GameDataConfig) loadPlayerLevelConfig() {
	g.GameDataMaps.PlayerLevelConfigMap = make(map[int32]*PlayerLevelConfig)
	for _, playerLevelConfig := range loadTableFromDb[PlayerLevelConfig](g.Db) {
		g.GameDataMaps.PlayerLevelConfigMap[playerLevelConfig.Level] = playerLevelConfig
	}
	logger.Info("PlayerLevelConfig Count: %v", len(g.GameDataMaps.PlayerLevelConfigMap))
}

func GetPlayerLevelConfig(level int32) *PlayerLevelConfig {
	value, exist := CONF.GameDataMaps.PlayerLevelConfigMap[level]
	if !exist {
		logger.Error("[ConfigNotFound] PlayerLevelConfig, level: %v", level)
		return nil
	}
	return value
}

func GetPlayerLevelConfigMap() map[int32]*PlayerLevelConfig {
	return CONF.GameDataMaps.PlayerLevelConfigMap
}
